package drg_group.wuxi_2022.MDC;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import drg_group.wuxi_2022.Base;
import drg_group.wuxi_2022.MedicalRecord;
import drg_group.wuxi_2022.ADRG.*;

public class MDCN{
    public static String group(MedicalRecord record){
        String[] mdc_zd={"N89.901","N73.606","N70.903","N85.001","C54.100","N80.801","N76.400","S37.810","N76.000x004","N89.001","C57.200","D39.708","Q50.401","S30.200x010","N82.501","N83.800x012","C79.800x222","D25.100x002","N83.500x004","N84.100","N87.000","Q52.103","N86.x02","N90.800x024","N85.101","A56.100x003+N74.4*","A18.114+N74.1*","Q50.502","E28.000","S39.902","S31.400x003","N83.203","S37.400","N85.811","N91.500","C53.000","N85.816","D39.700x001","A56.101+N74.4*","D26.100x002","N99.801","N92.400x003","N85.600","D39.903","C79.800x214","N88.201","N88.800x010","N90.701","N73.801","N82.102","N81.800x005","C58.x00","N88.400","N75.100","N95.100","C54.200","N94.200","N90.404","N70.900x003","D39.100x003","N83.800x016","N76.000x001","C51.200","N83.207","C45.100","D25.000","N82.200","Q85.900x016","D39.000x002","D06.900x002","Q85.900x047","N92.100x001","N81.200","Q50.300x101","C76.307","N83.800x021","D39.902","N73.001","N81.500x003","N89.300","N73.602","N90.000","N90.400","Q51.802","Q85.900x045","T83.303","N97.000x001","N81.203","N82.100x001","N94.600","N83.803","C48.100x006","D26.700","N83.601","C56.x00x003","N89.806","N93.901","D39.200x002","Q51.801","N99.807","Q56.300","N81.201","Q51.600","D39.704","N76.801","N76.601","T83.305","R93.800x006","T28.800x002","D20.103","N70.905","N85.805","D39.003","N80.600","N85.200","N71.902","N76.000x003","N76.600","Q51.300","S37.602","N89.807","Q52.400x007","N70.906","N83.100x002","C54.000","N81.202","N83.000x002","N83.401","N88.300","C55.x00","N92.000x002","C79.833","N82.103","N88.803","N80.804","N97.200x002","N85.300x001","Q27.814","E28.302","E89.400x002","A18.111+N74.1*","A59.002+N77.1*","T83.304","D39.004","N70.904","N73.203","N82.301","N98.900","Q52.401","C54.001","C79.600","Q50.000","N90.302","D07.303","N80.001","N89.809","N82.303","N76.100x001","Q52.104","N80.603","N76.500","D39.901","N86.x00x004","N73.101","T28.800x003","A56.003","D06.900","N80.800x010","C57.000x002","Q52.800x004","N80.200x001","N97.100x003","Q51.400","N83.201","N70.101","D39.201","N90.807","A54.004","N89.100","N91.200","N92.000x001","Q50.501","A56.004","N83.100","B26.800x009+N74.8*","N87.901","D07.304","N99.800x005","N90.001","N83.300x002","N85.401","N85.806","Q51.805","C54.800","N81.802","N83.902","D28.206","Q51.201","N76.000x006","Q50.200","N80.602","N75.000","C79.800x216","N71.901","N93.000x001","C51.800","C57.800x004","N84.302","N89.700","N92.200","N84.001","S37.600","D39.700x002","C57.301","N90.810","Q51.501","N73.201","E28.200x003","N89.810","N97.900","N75.802","D39.703","D28.203","Q52.601","S37.600x002","C79.800x202","N73.603","N95.900x001","N85.901","N94.807","N80.601","Q50.600","N83.204","Z31.100","N90.808","N85.403","N83.100x003","N89.000","N80.808","N90.902","R93.800x007","N86.x01","N70.104","N82.901","C79.823","Q51.001","N85.812","N70.000","N91.400","B37.300+N77.1*","D28.200x003","N89.600x002","E28.300x001","N82.300","N83.502","N81.801","A56.104+N74.4*","Q52.408","E89.400x001","Z31.201","Q51.202","Q52.402","Q51.502","D28.900","R87.800","D28.100","N90.803","N85.400","N89.200","N82.902","N76.401","C57.300","D39.702","N73.604","N82.900x003","N83.806","S31.400x002","N72.x00x003","N70.100","N82.101","B37.300x002+N77.1*","C79.800x220","N83.001","D25.200","N95.300x001","S31.402","D39.005","Q51.203","D39.200x001","D39.707","N90.802","C46.700x001","C57.802","N76.201","N88.000","N97.902","D25.900","N73.300","N92.600","D17.300x003","N87.101","N82.900","E28.300x008","N89.801","Z31.300x002","A54.200x004+N74.3*","D28.201","N94.805","N85.808","C54.900","D07.301","N76.101","Q52.300","N94.100","N94.808","N83.802","N81.101","N80.501","N88.101","D39.001","N76.000","N85.300","N76.200","I89.800x032","D06.100","N94.900","S38.200x006","N90.300","Q50.603","Q50.503","N83.811","T83.400","N71.001","N90.403","N90.800x025","T28.800x001","Q52.407","N81.601","N90.601","A51.400x009+N74.2*","C79.813","N81.803","N85.802","N89.805","N70.001","D27.x00","N73.903","N92.300","N85.600x001","T19.201","N87.001","N84.900","Q52.405","D07.200x002","E28.300x002","Q52.703","N80.200","N73.605","N83.801","D39.204","C79.800x228","N91.200x002","Q51.806","D18.000x824","C57.803","L29.200","N70.103","S38.200x002","R87.300","N76.001","N88.804","N80.303","N95.800","C57.702","Q52.404","Q52.500x001","N71.102","N76.301","A18.100x030+N77.0*","T28.300x002","N89.800x009","Q50.303","C53.801","N89.600x001","N90.100","C79.812","N83.206","N83.800x013","R87.700","N90.301","N90.805","N71.900x001","N73.800x002","D07.100","Q50.600x904","N72.x03","N88.900","N92.400x001","N89.804","N90.804","T19.300x001","B37.302+N77.1*","N80.809","D07.302","D27.x01","C79.822","C51.900","N80.805","B37.301+N77.1*","N95.200","N90.800x009","I89.000x019","C79.821","N98.000","R87.100","A18.112+N74.0*","D07.100x002","N80.807","N73.003","N75.900","N80.803","N81.000","Q52.101","N94.000","N99.201","N83.101","N90.700","N89.808","E28.301","N72.x02","N73.104","N90.200","N83.600","N92.500","A54.201+N74.3*","N73.500","N85.700","E28.800x002","N98.800","N90.809","C79.800x215","C79.814","Q27.813","N82.502","N95.101","Q51.100x001","N81.602","N90.101","R87.000","N71.101","S30.207","A56.100x004+N74.4*","N85.402","S37.410","C57.000","N83.807","N85.000x002","N73.002","Q51.808","C79.800x205","C51.001","Q51.800x012","N85.803","N80.800x007","N92.101","N92.400x004","N83.901","N85.003","N85.807","D07.000","E28.303","N85.800x003","Q52.406","D25.100x001","N76.802","N80.301","S31.401","Q50.100","D39.900x001","N83.800x015","A18.100x024+N74.1*","N83.804","N93.900","Q52.700x004","N73.202","T83.301","C79.800x209","N85.002","D06.700","Q51.803","S37.601","N72.x01","D26.900","Z31.200x003","N80.900","N88.805","D26.100","Q50.000x011","N81.300","N83.000","C57.101","N84.300","Q52.901","T28.300x001","I86.200","N88.802","N80.000","C53.100","N80.401","C79.800x218","N90.800x012","N83.300x001","N90.800x011","N91.100","N85.804","N89.601","Z52.800x001","N89.503","N90.401","N99.200","N84.000","N90.801","N97.101","N73.902","C57.300x001","S37.710","I89.800x033","Z01.800x003","E28.300x005","N71.002","N70.102","N94.500","N85.404","D25.900x001","C79.800x211","N90.800x010","A18.115+N74.1*","C79.800x219","D48.127","R87.600","Q50.601","N97.801","N89.600","Q51.000x001","D39.709","N98.200","N88.806","T83.400x001","N80.800x011","A18.113+N74.1*","R93.803","A54.102","N97.800x004","Q27.816","Q52.403","N80.100","N95.201","N89.803","N85.801","N97.200x001","N89.400","Q50.400","N81.600","C56.x00","N81.900","N88.200x001","D26.702","N76.300x001","C51.100","N81.500","N94.804","N97.901","N99.800x010","N96.x00x002","N94.802","N99.800x007","A60.000x003+N77.1*","R87.400","D28.200x002","N89.802","Z31.000x001","N82.500","C57.700","D39.705","N83.903","N84.301","N82.000","N85.813","Q50.301","N88.100","N93.801","N72.x00x006","D25.000x002","N90.901","D28.700x001","N89.501","N97.400x002","N81.100","T19.202","C79.800x223","N94.803","N73.601","D18.000x853","N85.000x004","I86.300","T28.300x003","N83.808","N90.806","N73.600","Q52.700x003","N91.300","N70.901","D28.000","N84.800x002","D28.205","A18.100x026+N74.1*","N83.202","D25.901","N83.812","N85.810","Q50.302","A54.003","D28.202","N88.801","S39.901","N85.500","Q52.701","D28.204","N73.400","S30.200x008","N95.000","Q51.000","N80.302","C52.x00","N90.402","Q50.000x021","D39.202","Z01.400x001","Q50.602","C53.900","S37.510","Q51.901","R87.200","I77.009","C57.400","D26.701","N81.102","C54.300","T83.302","D39.100x001","C57.100","N92.601","N84.200","C58.x00x003","C57.701","E28.100","Q56.200","N97.400x001","I89.000x018","D17.700x024","Z31.200","S37.500","M35.202+N77.8*","D39.101","N96.x00x003","N97.100x001","N92.400","N92.401","Q52.700x005","S31.400x001","S38.200x001","Q51.100","Z31.300x001","C79.824","N83.800x017","Q51.804","D39.002","N87.200x001","N90.600","N94.400","N70.900","N80.100x001","Q50.504","C57.900","C58.x00x002","D39.203","N75.801","N87.002","N99.300","N81.500x002","N83.700","D39.000x001","N80.806","C57.800x005","Q52.400x006","Q51.900","N83.102","N90.500","Q51.800x007","N32.004","N80.802","N85.100","N81.400","N94.800x009","C77.500x003","E28.900","N70.002","N98.300","N85.000","D39.710","Q56.400","N83.810","N83.503","N99.800x003","A18.100x032","N83.500x007","N94.300","D18.000x817","N80.300","C79.800x206","N70.900x007","N81.800x004","N89.502","N73.103","N91.000","C79.800x213","N82.801","Q51.800x011","N73.102","N83.205","N83.504","N88.102","D25.200x002","D18.000x854","D06.000","N89.101","N89.811","N97.300","N85.815","Q52.000","N73.501","N88.808","A18.102","N83.501","S37.610","N70.902","A54.005","N80.500","N83.805","Q52.200","N81.301","N85.809","N88.807","N82.401","C57.801","D18.000x856","N73.600x006","Q56.000","D39.706","C51.000","D28.000x002","E28.200","R87.500","N90.501","A56.002","N83.809","E30.900","S30.200x007","N94.806","E89.401","N87.900","D39.701","D07.200","N87.100","N85.814","N96.x00","N76.100x002","D26.000","C53.800","Q52.702","A18.100x019+N77.1*","N90.811","N98.100","Q50.600x903"};
        String[] dept_list={};
        if (!(true && Base.contains(mdc_zd,record.zdList[0]) && record.gender!=null && record.gender.equals("2"))){
            return "";
        }
        
        Base.groupMessages.putMessage(record.Index,"符合MDCN入组条件，匹配规则：主诊断匹配、女性");
        String result;

        result=NA1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NA2.group(record);
        if (result.length()>0){
            return result;
        }

        result=NB1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NC1.group(record);
        if (result.length()>0){
            return result;
        }

        result=ND1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NE1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NF1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NG1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NJ1.group(record);
        if (result.length()>0){
            return result;
        }

        if (record.ssList!=null && record.ssList.length>0  && Base.intersect(Base.SS_VALID,record.ssList)){
            Base.groupMessages.putMessage(record.Index,"符合NQY入组条件，存在有效手术操作："+String.join(",",Base.Intersect(record.ssList,Base.SS_VALID)));
            return "NQY";
        }

        result=NR1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NS1.group(record);
        if (result.length()>0){
            return result;
        }

        result=NZ1.group(record);
        if (result.length()>0){
            return result;
        }

        Base.groupMessages.putMessage(record.Index,"不符合MDCN的ADRG入组条件");
        return "";
    }
}

